package com.yy.device.config;

import com.yy.device.boot.DeviceServer;
import com.yy.device.boot.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * PLC服务器配置
 *
 * @author sunzhiqiang
 * @date 2022/06/16 10:02:09
 */
@Configuration
public class DeviceServerConfiguration {

    public static final String DEVICE_SERVER_PREFIX = "netty.server.device-server";

    @Value("${netty.server.device-server.port}")
    private Integer deviceServerPort;
    @Value("${netty.server.device-server.name}")
    private String deviceServerName;
    @Value("${netty.server.device-server.boss-size}")
    private Integer deviceServerBossSize;
    @Value("${netty.server.device-server.worker-size}")
    private Integer deviceServerWokerSize;

    @Value("${netty.server.device-server.options.so-backlog}")
    private Integer deviceServerSoBacklog;

    @Value("${netty.server.scoket-server.port}")
    private Integer scoketServerPort;

    /**
     * 获取设备服务器
     *
     * @return {@link DeviceServer}
     */
    @Bean
    @ConditionalOnProperty(prefix = DEVICE_SERVER_PREFIX, value = "enabled", havingValue = "true")
    public DeviceServer getDeviceServer() {
        return new DeviceServer(deviceServerPort,
                deviceServerBossSize,
                deviceServerWokerSize, deviceServerSoBacklog);
    }

    @Bean
    public WebSocketServer getSocketServer() {
        return new WebSocketServer(scoketServerPort);
    }


}
